package thingtest.game;

import java.util.Observable;

public class GameModel extends Thread{

	private Scenario scenario;
	private Player player;
	private boolean gameIsRunning;
	
	public GameModel(){
		
		this.scenario = new Scenario(640, 480);
		this.player = new Player();
		this.scenario.insertPlayer(player);
		gameIsRunning = false;
		
	}
	
	public void insertThing(Thing thing) {
		
		this.scenario.put(thing, thing.location());
		//this.setChanged();
		//this.notifyObservers();
	}

	public void advanceFrame() {

		this.scenario.makeAllThingsAdvanceAtCurrentSpeed();
		//this.setChanged();
		//this.notifyObservers();
		
	}

	public ListOfThings listOfThings() {
		return scenario.containedThings();
		
	}

	public Player getPlayer() {
		return this.player;
	}

	@Override
	public void run() {

		gameIsRunning = true;
		while(gameIsRunning){

			try {
				this.sleep(30);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			this.advanceFrame();

		}
		
	}

	public Scenario getScenario() {
		return scenario;
	}
	


}
